
/**
 * Created by beck on 2015/7/1.
 */
$("#psw_").mousedown(function(){
	$("#psw_").css({"color":"white","background":"#21c39c"});
});
$("#login").mousedown(function(){
	$("#login").css({"color":"white","background":"#21c39c"});
});
$("#psw_").mouseup(function(){
	$("#psw_").css({"color":"#21c39c","background":"none"});
});
$("#login").mouseup(function(){
	$("#login").css({"color":"#21c39c","background":"none"});
});
var storage = window.localStorage;
var groupid;
var c= 60;
var t;
var ph_num;
var psw;
function guest()
{
	alert("你现在是游客模式，部分功能不能使用！");
	var post="mid=13500000000&did=10000&groupid="+groupid;
	ajaxcocRequest('../../api/group/getgroupinfobymid','POST',post,function(msg){
		if(msg.code==100){ 
		 storage.setItem("userNumber","13500000000");
                    storage.setItem("userUrl", null);
         			storage.setItem("userName","游客");
         			storage.setItem("userSex","男");
         			storage.setItem("userNative","");
         			storage.setItem("userBirthday","");
         			storage.setItem("groupids",msg.datum.n0);
         			storage.setItem("groupNames",msg.datum.n1);
         			storage.setItem(window.sysgroupid+"_"+"currentGroupName",msg.datum.n1);
         			storage.setItem(window.sysgroupid+"_"+"logoUrl",msg.datum.n0);
         			storage.setItem(window.sysgroupid+"_"+"groupJob","游客");
         			storage.setItem("messageCount",0);
					storage.setItem("looktype","guest");
					storage.setItem(window.sysgroupid+"_"+"currentGroupid",groupid);
					storage.setItem("yunzokey", groupid);
					storage.setItem("defualtgroupid", groupid);
         			window.location = "main.html?mid=13500000000";  
		}else{
			alert("请检查您的设备网络是否正常！！！");
		}
	});
}

$(document).ready(function(){
	if(getUrlParam("groupid")!=null){
		groupid=getUrlParam("groupid");
	}else
	{
		groupid="88888888888888888888888888888888";
	}
	window.sysgroupid=groupid;
	 $("#guest").click(function(){
        guest();
    });
    $("#getCode").click(function(){
        $(this).unbind("click");
        timedCount();
        Login.GetCheckCode();
    });
	var $ph_num = $("#ph-num");
    var $ph_number =$("#ph-number");
	$ph_num.keyup(function(){
        var val = $(this).val();
        if(val ==''){
            $(this).css("color","black");
        }else{
            Login.CheckMobile($(this),val);
        }
    });
    $ph_number.keyup(function(){
        var val = $(this).val();
        if(val ==''){
            $(this).css("color","black");
        }else{
            Login.CheckMobile($(this),val);
        }
    });
    $(".forget").click(function(){
        window.location="third_frame/back_pwd.html";
    })
    $(".phone").click(function(){
        window.location="third_frame/enroll.html";
    })
});
function timedCount(){
    document.getElementById("getCode").innerHTML = c;
    c= c-1;
    if(c === 0){
        document.getElementById("getCode").innerHTML = "获取验证码";
        //$("#getCode").removeAttr("disabled");
        $("#getCode").bind("click");
        c = 60;
        return 0 ;
    }
    t= setTimeout("timedCount()",1000);
}
function click_code(){
	var mid1=$("#ph-num").val();
	var post="regmid="+mid1+"&type=1&groupid="+groupid;
	ajaxcocRequest('../../api/account/sendCode','POST',post,function(msg){
		if(msg.code==100){
			$("#huoqu").attr("onclick","rec();");
            var num=60;
            $("#huoqu").val("重新获取("+num+"s)");
            $("#huoqu").css("color","#999")
            to=setInterval(function(){
                num=num-1;
                $("#huoqu").val("重新获取("+num+"s)");
                if(num<=0){
                    clearInterval(to);
                    $("#huoqu").val("获取验证码");
                    $("#huoqu").css("color","#00abfd")
                    $("#huoqu").attr("onclick","click_code();");
                }
            },1000);
		}
		else{
			alert("验证码发送失败");
			alert(JSON.stringify(msg));
		}
	})
}
function rec(){
    alert("验证码已发送，请不要重复获取。")
}
function rec1(){
	alert("请输入正确的手机号。")
}
/*$("#ph-num").textInput(function(){
	alert(1)
	var re=/^(0|86|17951)?(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$/;
	if(re.test($('#ph-num').val())==false){
		$('#ph-num').css("color","#000");
		$("#huoqu").css("color","#00abfd")
		$("#huoqu").attr("onclick","click_code();");
	}
	else{
		$('#ph-num').css("color","#999");
		$("#huoqu").css("color","#999");
		$("#huoqu").attr("onclick","rec1();")
	}
});*/
var bind_name = 'input';
if (navigator.userAgent.indexOf("MSIE") != -1){
  bind_name = 'propertychange';
}
$('#ph-num').bind(bind_name, function(){
	var re=/^(0|86|17951)?(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$/;
	if(re.test($('#ph-num').val())!=false){
		$('#ph-num').css("color","#000");
		$("#huoqu").css("color","#00abfd")
		$("#huoqu").attr("onclick","click_code();");
	}
	else{
		$('#ph-num').css("color","#999");
		$("#huoqu").css("color","#999");
		$("#huoqu").attr("onclick","rec1();")
	}
})
var Login = $.extend({
     Logining:function(type){
        if(type ==0){
        	ph_num= $("#ph-num").val();
        	psw = $("#psw").val();
        }else{
        	ph_num = $("#ph-number").val();
            psw = $("#pwd").val();
        }
        if(ph_num.length==11)
        {    
        	if(psw.length>=6){
        	 //var Post ="mid="+ph_num+"&paswd="+psw+"&groupid="+groupid+"&type="+type;
        	 var Post = "mid="+ph_num+"&type="+type+"&groupid="+groupid+"&code="+psw;
        	 $("#loadIng_startStop").show();
             ajaxcocRequest('../../api/account/apptogrouploginformodilecode','POST',Post,function(msg){
            	 
                if(msg.code==100){   
                	
                    var localData =  window.localStorage;
                    localData.setItem("userNumber",msg.info.n0);
                    localData.setItem("userUrl", msg.info.n1);
         			localData.setItem("userName",msg.info.n2);
         			localData.setItem("userSex",msg.info.n3);
         			localData.setItem("userNative",msg.info.n4);
         			localData.setItem("userBirthday",msg.info.n5);
         			localData.setItem("groupids",msg.info.n6);
         			localData.setItem("groupNames",msg.info.n7);
         			localData.setItem(window.sysgroupid+"_"+"currentGroupName",msg.info.n8);
         			localData.setItem(window.sysgroupid+"_"+"logoUrl",msg.info.n9);
         			localData.setItem(window.sysgroupid+"_"+"groupJob",msg.info.n10);
         			localData.setItem("messageCount",msg.info.n11);
					localData.setItem("looktype",msg.info.n10);
					localData.setItem(window.sysgroupid+"_"+"currentGroupid",groupid);
					localData.setItem("yunzokey", groupid);
					localData.setItem("defualtgroupid", groupid);
         			window.location = "main.html?mid="+msg.info.n0;  	
                }
                else{
                    alert("登录失败,验证码或手机号不正确。");
                    $("#loadIng_startStop").hide();
                }
                
             });
        	}
        	else{
        		alert("请输入6位数验证码！")
        	}
        }
        else{
        	alert("请输入正确的手机号");
        }
        
           
            },
    CheckMobile:function(name,str){
        var rule = /^1\d{10}$/;
        if(rule.test(str)){
        		name.css("color","#000");
        		$("#huoqu").css("color","#00abfd")
        		$("#huoqu").attr("onclick","click_code();");
        	}else{
        		name.css("color","#999");
        		$("#huoqu").css("color","#999");
        		$("#huoqu").attr("onclick","rec1();")
        	}
        },
    GetCheckCode:function(){
        var $ph_num = $("#ph-number").val();
        var Post = "mid="+$ph_num;
        $.ajax({
            url:'../api/account/sendCode',
            type:'post',
            data:Post,
            success:function(msg){
                if(msg.code ==103){
                    alert(msg.message);
                }
            }
        });
    }
});
$("input").css("border-radius",$("input").height()+"px")
